package com.gotrade.ftpdemo.common;

import lombok.Getter;
import lombok.Setter;
import org.apache.commons.net.ftp.FTP;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.Base64;

/**
 * @author jason.tang
 * @create 2019-03-08 13:53
 * @description FTP Client 配置类
 */
@Getter
@Setter
@Component
@ConfigurationProperties(ignoreUnknownFields = false, prefix = "ftp.client")
public class FTPClientProperties {
    // ftp地址
    private String host;

    // 端口号
    private Integer port;

    // 登录用户
    private String username;

    // 登录密码
    private String password;

    // 根目录
    private String baseUrl;

    // 编码
    private String encoding;

    // 被动模式
    private boolean passiveMode;

    // 连接超时时间(秒)
    private Integer connectTimeout;

    // 传输超时时间(秒)
    private Integer dataTimeout;

    // 缓冲大小
    private Integer bufferSize;

    /**
     * 设置keepAlive
     * 单位:秒  0禁用
     * Zero (or less) disables
     */
    private Integer keepAliveTimeout;

    /**
     * 传输文件类型
     * in theory this should not be necessary as servers should default to ASCII
     * but they don't all do so - see NET-500
     */
    private Integer transferFileType = FTP.BINARY_FILE_TYPE;

    public String getPassword() {
        return new String(Base64.getDecoder().decode(this.password));
    }
}